//
//  VideoInfoView.m
//  XNSudai
//
//  Created by Carlson Lee on 2017/4/1.
//  Copyright © 2017年 xulu. All rights reserved.
//  音影资料view

#import "VideoInfoView.h"

@interface VideoInfoView ()
{
    void(^_block)(BOOL isComplete);
}
@property(nonatomic, strong)UIButton* infoBtn;
@property(nonatomic, strong)UIImageView* faceImg;
@property(nonatomic, strong)UILabel* infoLab;

@end

@implementation VideoInfoView

- (instancetype)init
{
    if(self = [super init]){
        [self setBackgroundColor:[UIColor whiteColor]];
    }
    return self;
}

- (void)setImg:(NSString *)imgStr describle:(NSString *)desStr WithBlock:(void (^)(BOOL))block
{
    [self.infoBtn setBackgroundImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];
    self.desStr = desStr;
    _block = block;
}

- (UIButton *)infoBtn
{
    if(!_infoBtn){
        _infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_infoBtn];
        [_infoBtn addTarget:self action:@selector(selectBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _infoBtn;
}

- (UIImageView *)faceImg
{
    if(!_faceImg){
        _faceImg = [[UIImageView alloc]init];
        [self addSubview:_faceImg];
    }
    return _faceImg;
}

- (UILabel *)infoLab
{
    if(!_infoLab){
        _infoLab = [UILabel new];
        [self addSubview:_infoLab];
        [_infoLab setBackgroundColor:[UIColor clearColor]];
        [_infoLab setTextColor:UIColorFromRGB(0x3c3342)];
        [_infoLab setTextAlignment:NSTextAlignmentCenter];
        [_infoLab setFont:SDFont(15, FONT_TYPE_REGULAR)];
    }
    return _infoLab;
}

- (void)setFace:(UIImage *)face
{
    _face = face;
}

- (void)setDesStr:(NSString *)desStr
{
    _desStr = desStr;
    self.infoLab.text = _desStr;
}

- (void)selectBtn
{
    if(_block){
        _block(YES);
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    UIImage* img = self.infoBtn.currentBackgroundImage;
    CGSize dsize = SDSize(_desStr, SDFont(15, FONT_TYPE_REGULAR), CGSizeZero);
    self.infoBtn.frame = CGRectMake((UIFrameW(self)-img.size.width)/2, (UIFrameH(self)-img.size.height-dsize.height-20*ScaleX)/2, img.size.width, img.size.height);
    self.infoLab.frame = CGRectMake((UIFrameW(self)-dsize.width)/2, CGRectGetMaxY(self.infoBtn.frame)+20*ScaleX, dsize.width, dsize.height);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
